clear
set more off, perm
cd /Users/zachbrown/Projects/PriceTransparency/Data/
global output /Users/zachbrown/Projects/PriceTransparency/Output

///////////////////////////
// Allowed Amount
///////////////////////////

// open visit dataset
use clean/radiology_visit_3.dta, clear

// Make treatment indicator
gen post = (ym>=ym(2007,3))
gen web_post = (visit_on_web==1 & post==1)

drop if ym>ym(2010, 11)

// By half year estimates
gen timeper = yh(year(from_date), halfyear(from_date))
format timeper %th
tab timeper

gen timeper_int = timeper if visit_on_web==1
xi i.timeper_int, noomit

foreach var of varlist _Itimeper_i_* {
	replace `var' = 0 if `var'==.
	}

// Omitted group
disp yh(2006, 2)
drop _Itimeper_i_93

// Set X controls 
global ctr_vars1 = "has_copay has_coin##deduct_type age male i.charlindex zip_mean_income zip_pct_ba i.rural_class i.ym i.std_product_type i.payer_id"
global ctr_vars2 = "age male i.charlindex zip_mean_income zip_pct_ba i.rural_class i.ym i.std_product_type i.payer_id"

reghdfe ln_amt_allowed _Itimeper_i_* $ctr_vars2, absorb(proc_id_radio)

parmest, norestore
keep if strpos(parm,"_Itimeper_i_")>0
gen timeper_str = substr(parm,13,3)
destring timeper_str, gen(timeper)

replace timeper = timeper - 94

local new = _N + 1
set obs `new'
replace timeper = -1 if parm==""
replace estimate = 0 if parm==""
sort timeper
order timeper

gen years = timeper/2 + 0.5

twoway 	(line estimate years, color(black) lwidth(medthin)) ///
	(rcap max95 min95 years, color(gs3) lwidth(medthin)), ///
	xline(0, lwidth(thin) lp(dash) lcolor(gs6) ) ///
	yline(0, lwidth(thin) lp(dash) lcolor(gs6)) ///
	ylabel(-.1(0.02).06, tposition(inside) angle(horizontal) format(%04.2f))  ///
	xlabel(-2(1)4, tposition(inside)) /// 
	legend(off) /// 
	scheme(s1mono) ytitle("Effect (log points)") xtitle("Years Since Introduction of Website") ///
	graphregion(margin(r+5 l-2)) plotregion(margin(r+2 l+2))
	
graph export $output/base_effect_chart_allowed.pdf, replace 



///////////////////////////
// OOP Amount
///////////////////////////

// open visit dataset
use clean/radiology_visit_3.dta, clear

// Make treatment indicator
gen post = (ym>=ym(2007,3))
gen web_post = (visit_on_web==1 & post==1)

drop if ym>ym(2010, 11)

// By half year estimates
gen timeper = yh(year(from_date), halfyear(from_date))
format timeper %th
tab timeper

gen timeper_int = timeper if visit_on_web==1
xi i.timeper_int, noomit

foreach var of varlist _Itimeper_i_* {
	replace `var' = 0 if `var'==.
	}

// Omitted group
disp yh(2006, 2)
drop _Itimeper_i_93

// Set X controls 
global ctr_vars1 = "has_copay has_coin##deduct_type age male i.charlindex zip_mean_income zip_pct_ba i.rural_class i.ym i.std_product_type i.payer_id"
global ctr_vars2 = "age male i.charlindex zip_mean_income zip_pct_ba i.rural_class i.ym i.std_product_type i.payer_id"

reghdfe ln_amt_member_oop _Itimeper_i_* $ctr_vars1, absorb(proc_id_radio)

parmest, norestore
keep if strpos(parm,"_Itimeper_i_")>0
gen timeper_str = substr(parm,13,3)
destring timeper_str, gen(timeper)

replace timeper = timeper - 94

local new = _N + 1
set obs `new'
replace timeper = -1 if parm==""
replace estimate = 0 if parm==""
sort timeper
order timeper

gen years = timeper/2 + 0.5

twoway 	(line estimate years, color(black) lwidth(medthin)) ///
	(rcap max95 min95 years, color(gs3) lwidth(medthin)), ///
	xline(0, lwidth(thin) lp(dash) lcolor(gs6) ) ///
	yline(0, lwidth(thin) lp(dash) lcolor(gs6)) ///
	ylabel(-.15(0.02).06, tposition(inside) angle(horizontal) format(%04.2f))  ///
	xlabel(-2(1)4, tposition(inside)) /// 
	legend(off) /// 
	scheme(s1mono) ytitle("Effect (log points)") xtitle("Years Since Introduction of Website") ///
	graphregion(margin(r+5 l-2)) plotregion(margin(r+2 l+2))
	
graph export $output/base_effect_chart_oop.pdf, replace 





///////////////////////////
// Paid Amount
///////////////////////////

// open visit dataset
use clean/radiology_visit_3.dta, clear

// Make treatment indicator
gen post = (ym>=ym(2007,3))
gen web_post = (visit_on_web==1 & post==1)

drop if ym>ym(2010, 11)

// By half year estimates
gen timeper = yh(year(from_date), halfyear(from_date))
format timeper %th
tab timeper

gen timeper_int = timeper if visit_on_web==1
xi i.timeper_int, noomit

foreach var of varlist _Itimeper_i_* {
	replace `var' = 0 if `var'==.
	}

// Omitted group
disp yh(2006, 2)
drop _Itimeper_i_93

// Set X controls 
global ctr_vars1 = "has_copay has_coin##deduct_type age male i.charlindex zip_mean_income zip_pct_ba i.rural_class i.ym i.std_product_type i.payer_id"
global ctr_vars2 = "age male i.charlindex zip_mean_income zip_pct_ba i.rural_class i.ym i.std_product_type i.payer_id"

reghdfe ln_amt_paid _Itimeper_i_* $ctr_vars1, absorb(proc_id_radio)

parmest, norestore
keep if strpos(parm,"_Itimeper_i_")>0
gen timeper_str = substr(parm,13,3)
destring timeper_str, gen(timeper)

replace timeper = timeper - 94

local new = _N + 1
set obs `new'
replace timeper = -1 if parm==""
replace estimate = 0 if parm==""
sort timeper
order timeper

gen years = timeper/2 + 0.5

twoway 	(line estimate years, color(black) lwidth(medthin)) ///
	(rcap max95 min95 years, color(gs3) lwidth(medthin)), ///
	xline(0, lwidth(thin) lp(dash) lcolor(gs6) ) ///
	yline(0, lwidth(thin) lp(dash) lcolor(gs6)) ///
	ylabel(-.15(0.02).06, tposition(inside) angle(horizontal) format(%04.2f))  ///
	xlabel(-2(1)4, tposition(inside)) /// 
	legend(off) /// 
	scheme(s1mono) ytitle("Effect (log points)") xtitle("Years Since Introduction of Website") ///
	graphregion(margin(r+5 l-2)) plotregion(margin(r+2 l+2))
	
graph export $output/base_effect_chart_paid.pdf, replace 

